#!/usr/bin/env python3
"""
Stripe集成演示应用 - 重构版本
实现客户管理、产品管理、订阅管理的完整功能
使用分层架构设计
"""

import logging
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from utils.config import Config
from api import (
    customer_router,
    product_router,
    subscription_router,
    portal_router,
    system_router,
    webhook_router
)

# 配置日志
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# 初始化配置
Config.initialize()

# 初始化FastAPI应用
app = FastAPI(
    title="Stripe集成演示系统",
    description="完整的客户、产品、订阅管理系统 - 重构版本",
    version="2.0.0"
)

# 添加CORS中间件
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 注册路由
app.include_router(system_router)
app.include_router(customer_router)
app.include_router(product_router)
app.include_router(subscription_router)
app.include_router(portal_router)
app.include_router(webhook_router)

logger.info("Stripe集成演示系统启动完成")
logger.info(f"应用地址: {Config.APP_HOST}:{Config.APP_PORT}")
logger.info("API文档地址: http://localhost:8003/docs")

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host=Config.APP_HOST, port=Config.APP_PORT)
